//写一个函数，判断一个字符串是否为另外一个字符串旋转之后的字符串。
//例如：给定s1 = AABCD和s2 = BCDAA，返回1
//给定s1 = abcd和s2 = ACBD，返回0.
//AABCD左旋一个字符得到ABCDA
//AABCD左旋两个字符得到BCDAA
//AABCD右旋一个字符得到DAABC
#include<assert.h>
#include<string.h>
int IsRevolve(char* p, char* sour)
{
	assert(p && sour);

	int plen = strlen(p);
	int sourlen = strlen(sour);
	if (sourlen != plen)
	{
		return 0;
	}
	//复制一份数组
	char* copy = (char*)malloc(sizeof(char) * 2 * sourlen+1);
	strcpy(copy, sour);
	strcpy(copy + sourlen , sour);
	int count = 0;
	char* head = p;
	while (*copy!='\0')
	{
		//找第一个相等的元素，如果没找到，就返回0
		if (*copy != *p)
		{
			copy++;
			count++;
			if (count >= sourlen)
			{
				return 0;
			}
		}
		//开始比较
		else
		{
			int len = sourlen;
			head = p;
			while (len)
			{
				if (*copy == *head)
				{
					copy++;
					head++;
					len--;
				}
				else
				{
					break;
				}
			}
			if (len == 0)
			{
				return 1;
			}
		}
	}
	return 0;
}
//AABCDAABCD
//BCDAA
//AABACD
//ACDAAB
int main()
{
	char* arr1 = "AABACD";
	char* arr2 = "ACDAAB";

	int flag=IsRevolve(arr2, arr1);
	printf("%d ", flag);
	return 0;
}